package com.wxsong.authplatform.authweb.controller.report;

import com.wxsong.authplatform.authweb.report.IReportBuild;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.j2ee.servlets.ImageServlet;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;

@Controller
public class ReportController {

    @RequestMapping("/exportPDF")
    public void exportReport(HttpServletRequest request, HttpServletResponse response){

        try {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            response.setContentType("text/html");
            response.setContentType("application/pdf");
            IReportBuild.exportReport(request, response);

        } catch (JRException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
